var UserTutortel = app.controller('UserTutortel', function($http, $scope, $rootScope, $location,$cordovaDevice,$cordovaChat,UserTutortelData) {
	try{
		$rootScope.showf=false;
		$scope.tel='';
		$scope.show = false;
		$scope.busy = false;
		$scope.dobusy = false;
		$rootScope.code_value = '获取验证码';
		if($rootScope.btrs1_tel!=undefined&&$rootScope.btrs1_tel!=""&&$rootScope.btrs1_tel!=null){
			$scope.tel=$rootScope.btrs1_tel;
		}
		
		$scope.keyPress=function(e){
			if(e.which==13){
				$scope.save();
			}
		}
		$scope.keyPressNext=function(e){
			if(e.which==13||e.which==9){
				$scope.save();
			}
		}
		$scope.get_code=function(){
			if($scope.busy){
				return false;
			}
			if($scope.tel == ""){
				showtoast("请输入手机号码");
				return false;
			}
			$scope.busy=true;
			var url=SITE_URL+"index.php?app=userapp&act=authcode&t="+$scope.tel+"&callback=JSON_CALLBACK&type=regtutor";
			$http.jsonp(url).success(function(data) {
				if(data.done){
					
					$scope.code_num = 60;
					$rootScope.code_value = '秒后重发';
					var myTime = setInterval(function() {
						$scope.code_num--;
						$scope.$apply(); // 通知视图模型的变化

						if($scope.code_num<=0){

							$scope.busy=false;
							$rootScope.code_value = '获取验证码';
							$scope.code_num =  '';
							clearInterval(myTime);
							$scope.$apply();
						}
					}, 1000);	
				}else{
					$scope.busy = false;
				}
			}).error(function(){$scope.busy = false;});
		}
		//保存信息
		$scope.save=function(){
			if($scope.dobusy){
				return false;
			}
			if($scope.tel == ""){
				showtoast("请输入手机号码");
				return false;
			}
			if(!$scope.validate_code){
				showtoast("请输入验证码");
				return false;
			}
			$scope.dobusy=true;
			var url=SITE_URL+"index.php?app=usermyapp&act=validatetel&tel="+$scope.tel+"&callback=JSON_CALLBACK&code="+$scope.validate_code;
			$http.jsonp(url).success(function(data) {
				if(data.done){
					$rootScope.btrs1_tel=$scope.tel;
					$rootScope.back();	
				}else{
					$scope.dobusy = false;
				}
			}).error(function(){$scope.dobusy = false;});
		}
		
	}
	catch (e) {
		showcatch(e);
	}
});
UserTutortel.UserTutortelData=function($q, $http,$stateParams,$rootScope){
	try {
		var data = [];
		var def = $q.defer();
		if(window.localStorage.u==undefined||window.localStorage.u==null||window.localStorage.u==""){			
			$rootScope.go("loginmain");
		}else{
			def.resolve(data);
		}
		
		return def.promise;
	} catch (e) {
		showcatch(e);
	}
}